package com.smag.web.controller.echarts.pie;

import com.smag.common.annotation.Log;
import com.smag.common.core.controller.BaseController;
import com.smag.common.core.domain.AjaxResult;
import com.smag.common.core.page.TableDataInfo;
import com.smag.common.enums.BusinessType;
import com.smag.common.utils.poi.ExcelUtil;
import com.smag.echarts.domain.EchartsPieNatural;
import com.smag.echarts.service.EchartsPieNaturalService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController("pieNaturalController")
@RequestMapping("/echarts/pie/natural")
public class NaturalController extends BaseController {
    @Resource
    private EchartsPieNaturalService echartsPieNaturalService;
    @GetMapping("/listAll")
    public AjaxResult getNaturalList(){
        return echartsPieNaturalService.getNaturalList();
    }

    @PreAuthorize("@ss.hasPermi('system:natural:list')")
    @GetMapping("/list")
    public TableDataInfo list(EchartsPieNatural echartsPieNatural)
    {
        startPage();
        List<EchartsPieNatural> list = echartsPieNaturalService.selectEchartsPieNaturalList(echartsPieNatural);
        return getDataTable(list);
    }

    /**
     * 导出自然灾害列表
     */
    @PreAuthorize("@ss.hasPermi('system:natural:export')")
    @Log(title = "自然灾害", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EchartsPieNatural echartsPieNatural)
    {
        List<EchartsPieNatural> list = echartsPieNaturalService.selectEchartsPieNaturalList(echartsPieNatural);
        ExcelUtil<EchartsPieNatural> util = new ExcelUtil<EchartsPieNatural>(EchartsPieNatural.class);
        util.exportExcel(response, list, "病虫灾害数据");
    }

    /**
     * 获取自然灾害详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:natural:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return echartsPieNaturalService.selectEchartsPieNaturalById(id);
    }

    /**
     * 新增自然灾害
     */
    @PreAuthorize("@ss.hasPermi('system:natural:add')")
    @Log(title = "自然灾害", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EchartsPieNatural echartsPieNatural)
    {
        return echartsPieNaturalService.insertEchartsPieNatural(echartsPieNatural);
    }

    /**
     * 修改自然灾害
     */
    @PreAuthorize("@ss.hasPermi('system:natural:edit')")
    @Log(title = "自然灾害", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EchartsPieNatural echartsPieNatural)
    {
        return echartsPieNaturalService.updateEchartsPieNatural(echartsPieNatural);
    }

    /**
     * 删除自然灾害
     */
    @PreAuthorize("@ss.hasPermi('system:natural:remove')")
    @Log(title = "自然灾害", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return echartsPieNaturalService.deleteEchartsPieNaturalByIds(ids);
    }
}
